home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / sys_util / taskv1 / tasklist.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-09-24  |  30.6 KB  |  811 lines

  1. VERSION 2.00
  2. Begin Form TaskList 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    ClientHeight    =   4905
  6.    ClientLeft      =   1170
  7.    ClientTop       =   1470
  8.    ClientWidth     =   5640
  9.    ClipControls    =   0   'False
  10.    ControlBox      =   0   'False
  11.    Height          =   5310
  12.    Icon            =   TASKLIST.FRX:0000
  13.    KeyPreview      =   -1  'True
  14.    Left            =   1110
  15.    LinkTopic       =   "Form1"
  16.    MaxButton       =   0   'False
  17.    MinButton       =   0   'False
  18.    ScaleHeight     =   4905
  19.    ScaleWidth      =   5640
  20.    Top             =   1125
  21.    Width           =   5760
  22.    Begin PictureBox Picture1 
  23.       AutoRedraw      =   -1  'True
  24.       BackColor       =   &H00C0C0C0&
  25.       Height          =   525
  26.       Left            =   4515
  27.       ScaleHeight     =   495
  28.       ScaleWidth      =   480
  29.       TabIndex        =   14
  30.       Top             =   60
  31.       Visible         =   0   'False
  32.       Width           =   510
  33.    End
  34.    Begin OptionButton UseModules 
  35.       BackColor       =   &H00C0C0C0&
  36.       Caption         =   "Walk Module List"
  37.       FontBold        =   0   'False
  38.       FontItalic      =   0   'False
  39.       FontName        =   "Small Fonts"
  40.       FontSize        =   6.75
  41.       FontStrikethru  =   0   'False
  42.       FontUnderline   =   0   'False
  43.       Height          =   285
  44.       Left            =   4140
  45.       TabIndex        =   13
  46.       Top             =   3585
  47.       Width           =   1395
  48.    End
  49.    Begin OptionButton UseTasks 
  50.       BackColor       =   &H00C0C0C0&
  51.       Caption         =   "Walk Task List"
  52.       FontBold        =   0   'False
  53.       FontItalic      =   0   'False
  54.       FontName        =   "Small Fonts"
  55.       FontSize        =   6.75
  56.       FontStrikethru  =   0   'False
  57.       FontUnderline   =   0   'False
  58.       Height          =   285
  59.       Left            =   2865
  60.       TabIndex        =   12
  61.       Top             =   3585
  62.       Width           =   1245
  63.    End
  64.    Begin OptionButton UseWins 
  65.       BackColor       =   &H00C0C0C0&
  66.       Caption         =   "Scan Windows"
  67.       FontBold        =   0   'False
  68.       FontItalic      =   0   'False
  69.       FontName        =   "Small Fonts"
  70.       FontSize        =   6.75
  71.       FontStrikethru  =   0   'False
  72.       FontUnderline   =   0   'False
  73.       Height          =   285
  74.       Left            =   1575
  75.       TabIndex        =   11
  76.       Top             =   3585
  77.       Value           =   -1  'True
  78.       Width           =   1245
  79.    End
  80.    Begin CommandButton RefreshList 
  81.       Caption         =   "Re&fresh"
  82.       Default         =   -1  'True
  83.       FontBold        =   0   'False
  84.       FontItalic      =   0   'False
  85.       FontName        =   "MS Sans Serif"
  86.       FontSize        =   8.25
  87.       FontStrikethru  =   0   'False
  88.       FontUnderline   =   0   'False
  89.       Height          =   390
  90.       Left            =   120
  91.       TabIndex        =   10
  92.       Top             =   3525
  93.       Width           =   1300
  94.    End
  95.    Begin CommandButton NukeTask 
  96.       Caption         =   "&Nuke Task"
  97.       Enabled         =   0   'False
  98.       FontBold        =   0   'False
  99.       FontItalic      =   0   'False
  100.       FontName        =   "MS Sans Serif"
  101.       FontSize        =   8.25
  102.       FontStrikethru  =   0   'False
  103.       FontUnderline   =   0   'False
  104.       Height          =   390
  105.       Left            =   4245
  106.       TabIndex        =   9
  107.       Top             =   3975
  108.       Width           =   1300
  109.    End
  110.    Begin CommandButton CloseTask 
  111.       Caption         =   "&Close Task"
  112.       Enabled         =   0   'False
  113.       FontBold        =   0   'False
  114.       FontItalic      =   0   'False
  115.       FontName        =   "MS Sans Serif"
  116.       FontSize        =   8.25
  117.       FontStrikethru  =   0   'False
  118.       FontUnderline   =   0   'False
  119.       Height          =   390
  120.       Left            =   2865
  121.       TabIndex        =   8
  122.       Top             =   3975
  123.       Width           =   1300
  124.    End
  125.    Begin CommandButton SwitchTo 
  126.       Caption         =   "&Switch To"
  127.       Enabled         =   0   'False
  128.       FontBold        =   0   'False
  129.       FontItalic      =   0   'False
  130.       FontName        =   "MS Sans Serif"
  131.       FontSize        =   8.25
  132.       FontStrikethru  =   0   'False
  133.       FontUnderline   =   0   'False
  134.       Height          =   390
  135.       Left            =   1500
  136.       TabIndex        =   7
  137.       Top             =   3975
  138.       Width           =   1300
  139.    End
  140.    Begin CommandButton ClassInfo 
  141.       Caption         =   "Class &Info"
  142.       Enabled         =   0   'False
  143.       FontBold        =   0   'False
  144.       FontItalic      =   0   'False
  145.       FontName        =   "MS Sans Serif"
  146.       FontSize        =   8.25
  147.       FontStrikethru  =   0   'False
  148.       FontUnderline   =   0   'False
  149.       Height          =   390
  150.       Left            =   120
  151.       TabIndex        =   6
  152.       Top             =   3975
  153.       Width           =   1300
  154.    End
  155.    Begin CommandButton ArrangeIcons 
  156.       Caption         =   "Arrang&e icons"
  157.       FontBold        =   0   'False
  158.       FontItalic      =   0   'False
  159.       FontName        =   "MS Sans Serif"
  160.       FontSize        =   8.25
  161.       FontStrikethru  =   0   'False
  162.       FontUnderline   =   0   'False
  163.       Height          =   390
  164.       Left            =   4245
  165.       TabIndex        =   5
  166.       Top             =   4425
  167.       Width           =   1300
  168.    End
  169.    Begin CommandButton TileWindows 
  170.       Caption         =   "&Tile"
  171.       FontBold        =   0   'False
  172.       FontItalic      =   0   'False
  173.       FontName        =   "MS Sans Serif"
  174.       FontSize        =   8.25
  175.       FontStrikethru  =   0   'False
  176.       FontUnderline   =   0   'False
  177.       Height          =   390
  178.       Left            =   2865
  179.       TabIndex        =   3
  180.       Top             =   4425
  181.       Width           =   1300
  182.    End
  183.    Begin CommandButton CascadeWindows 
  184.       Caption         =   "C&ascade"
  185.       FontBold        =   0   'False
  186.       FontItalic      =   0   'False
  187.       FontName        =   "MS Sans Serif"
  188.       FontSize        =   8.25
  189.       FontStrikethru  =   0   'False
  190.       FontUnderline   =   0   'False
  191.       Height          =   390
  192.       Left            =   1500
  193.       TabIndex        =   2
  194.       Top             =   4425
  195.       Width           =   1300
  196.    End
  197.    Begin CommandButton RunProgram 
  198.       Caption         =   "&Run ..."
  199.       FontBold        =   0   'False
  200.       FontItalic      =   0   'False
  201.       FontName        =   "MS Sans Serif"
  202.       FontSize        =   8.25
  203.       FontStrikethru  =   0   'False
  204.       FontUnderline   =   0   'False
  205.       Height          =   390
  206.       Left            =   120
  207.       TabIndex        =   1
  208.       Top             =   4425
  209.       Width           =   1300
  210.    End
  211.    Begin MListBox List1 
  212.       AddItemHeight   =   0
  213.       Alignment       =   1  'Left
  214.       AllowFocusRect  =   0   'False
  215.       BackColor       =   &H00C0C0C0&
  216.       BorderStyle     =   2  'Inset
  217.       CheckColor      =   &H00000000&
  218.       CheckStyle      =   0  'Cross Style
  219.       DefPicture      =   TASKLIST.FRX:0302
  220.       DrawRegions     =   2
  221.       EnableVirtualMsgs=   0   'False
  222.       ExtendedSelect  =   0   'False
  223.       FallColor       =   &H00808080&
  224.       FindDirection   =   0  'Forward
  225.       FindResult      =   0  'Update ListIndex
  226.       FontBold        =   0   'False
  227.       FontItalic      =   0   'False
  228.       FontName        =   "MS Sans Serif"
  229.       FontSize        =   8.25
  230.       FontStrikethru  =   0   'False
  231.       FontUnderline   =   0   'False
  232.       GridColor       =   &H00808080&
  233.       GridStyle       =   0  'Solid
  234.       Height          =   3105
  235.       HiliteBackColor =   &H00FF0000&
  236.       HiliteForeColor =   &H00FFFFFF&
  237.       HorizontalGrids =   -1  'True
  238.       ImageRegion     =   1
  239.       ImageType       =   1  'Bitmap
  240.       ItemHeight      =   610
  241.       ItemWidth       =   1560
  242.       Left            =   120
  243.       ListBoxStyle    =   0  'Fixed
  244.       MaskingColor    =   &H00C0C0C0&
  245.       MultiColumn     =   0   'False
  246.       MultiSelect     =   0   'False
  247.       NoIntegralHeight=   0   'False
  248.       OwnerDraw       =   0   'False
  249.       RiseColor       =   &H00FFFFFF&
  250.       SelectMode      =   0  'Normal
  251.       SortColumn      =   0
  252.       Sorted          =   0   'False
  253.       StringCompare   =   0  'Case Sensitive
  254.       TabIndex        =   0
  255.       Top             =   330
  256.       Version         =   "04.50"
  257.       VerticalGrids   =   0   'False
  258.       VirtualMsgZone  =   0
  259.       Width           =   5415
  260.    End
  261.    Begin MsgBlaster Msg1 
  262.       Prop8           =   "Click on ""..."" for the About Box ---->"
  263.       Prop9           =   "Click on ""..."" for the Message Center --->"
  264.       Left            =   5115
  265.       MsgList         =   TASKLIST.FRX:059C
  266.       MsgPassage      =   TASKLIST.FRX:0600
  267.       TargetName      =   "TaskList"
  268.       Top             =   45
  269.       UserMsgs        =   TASKLIST.FRX:0632
  270.       Version         =   "2.0"
  271.    End
  272.    Begin Label CaptionLabel 
  273.       AutoSize        =   -1  'True
  274.       BackColor       =   &H000000FF&
  275.       BackStyle       =   0  'Transparent
  276.       Caption         =   "Task List (traditional) - Copyright 
  277. 1994 michiel de bruijn     v1.01"
  278.       FontBold        =   -1  'True
  279.       FontItalic      =   0   'False
  280.       FontName        =   "Small Fonts"
  281.       FontSize        =   7.5
  282.       FontStrikethru  =   0   'False
  283.       FontUnderline   =   0   'False
  284.       ForeColor       =   &H00FFFFFF&
  285.       Height          =   180
  286.       Left            =   255
  287.       TabIndex        =   4
  288.       Top             =   15
  289.       Width           =   5325
  290.    End
  291. '====================================================================================
  292. 'TaskList.Frm - Copyright 
  293. 1994 michiel de bruijn, Rotterdam, The Netherlands
  294. ' Released for public use 16/08/1994. See TASKLIST.WRI for licensing details
  295. '====================================================================================
  296. DefInt A-Z
  297. Dim mScreenRect As rect
  298. Dim mCaptionColor&, mInSysMenu%, mhSysMenu%
  299. Static Sub AddTaskEntryToList (te As TASKENTRY, hWndTest%)
  300. 'AddTaskEntryToList: add the icon and task information for
  301. ' the TASKENTRY to our list
  302. CRLF$ = Chr$(13) & Chr$(10)
  303. 'First, get more information on the Task Module
  304. '  (we need the path to extract the icon)
  305. Dim mo As MODULEENTRY
  306. mo.dwSize = Len(mo)
  307. res% = ModuleFindName(mo, te.szModule)
  308. If res% = 0 Then
  309.     MsgBox "Could not retrieve module information for " & te.szModule, 48, "Error"
  310.     List1.AddItem ZTrim$(te.szModule) & CRLF$ & "(error getting module information)"
  311.     Exit Sub
  312. End If
  313. 'Then, extract the first Icon from the file we just found
  314. '  into our Picture1 control
  315. fil$ = ZTrim$(mo.szExePath)
  316. hIcon% = ExtractIcon(hInst%, fil$, 0)
  317. Picture1.Picture = LoadPicture("")
  318. res% = DrawIcon%(Picture1.hDC, 0, 0, hIcon%)
  319. 'Destroy the icon, releasing its memory
  320. res% = DestroyIcon(hIcon%)
  321. 'Get the (main) Window title for this task, if the caller
  322. '  did not specify it
  323. If hWndTest% = 0 Then
  324.     hWndTest% = GetWindow(Me.hWnd, GW_HWNDFIRST)
  325.     While hWndTest%
  326.         If GetWindow(hWndTest%, GW_OWNER) = 0 Then
  327.             hInst% = GetWindowWord(hWndTest%, GWW_HINSTANCE)
  328.             If hInst% = te.hInstance Then GoTo UglyBailOut  'Yup!
  329.         End If
  330.         hWndTest% = GetWindow(hWndTest%, GW_HWNDNEXT)
  331.     Wend
  332. End If
  333. UglyBailOut:
  334. buf$ = Space$(256)
  335. res% = GetWindowText(hWndTest%, buf$, 256)
  336. If res% < 2 Then buf$ = "(No window title)" & Chr$(0)
  337. 'Display Window/task info and type
  338. flags$ = "hWnd=" & Hex4$(hWndTest%) & ", hTask=" & Hex4$(te.hTask) & ", hInstance=" & Hex4$(te.hInstance) & ", hModule=" & Hex4$(te.hModule)
  339. If IsWindowVisible(hWndTest%) = 0 Then flags2$ = "[invisible] " Else flags2$ = ""
  340. If IsIconic(hWndTest%) <> 0 Then flags2$ = flags2$ & "[minimized] "
  341. If IsZoomed(hWndTest%) <> 0 Then flags2$ = flags2$ & "[maximized] "
  342. List1.AddItem fil$ & " (" & ZTrim$(te.szModule) & ") " & flags2$ & CRLF$ & ZTrim$(buf$) & CRLF$ & flags$
  343. List1.ItemPicture(List1.ListCount - 1) = Picture1.Image
  344. List1.ItemData(List1.ListCount - 1) = hWndTest%
  345. End Sub
  346. Sub ArrangeIcons_Click ()
  347. 'ArrangeIcons: Arrange all Icons on the Desktop
  348. res% = ArrangeIconicWindows(GetDeskTopWindow())
  349. End Sub
  350. Static Sub BuildModuleList ()
  351. 'BuildModuleList: Build Module List by walking the MODULEENTRY struct list
  352. CRLF$ = Chr$(13) & Chr$(10)
  353. Dim mo As MODULEENTRY
  354. mo.dwSize = Len(mo)
  355. screen.MousePointer = 11
  356. yield% = DoEvents()
  357. If ModuleFirst(mo) = 0 Then
  358.     MsgBox "Could not retrieve the first module in the module list. This is probably due to a corrupted system or an incompatible Windows version.", 16, "Fatal Error"
  359.     DoEnd
  360. End If
  361.     'Extract the first Icon from the module file into our Picture1 control
  362.     fil$ = ZTrim$(mo.szExePath)
  363.     hIcon% = ExtractIcon(hInst%, fil$, 0)
  364.     Picture1.Picture = LoadPicture("")
  365.     res% = DrawIcon%(Picture1.hDC, 0, 0, hIcon%)
  366.     'Destroy the icon, releasing its memory
  367.     res% = DestroyIcon(hIcon%)
  368.     List1.AddItem ZTrim$(mo.szExePath) & " (" & ZTrim$(mo.szModule) & ")" & CRLF$ & "wcUsage=" & Hex4$(mo.wcUsage) & ", hModule=" & Hex4$(mo.hModule)
  369.     List1.ItemPicture(List1.ListCount - 1) = Picture1.Image
  370.     List1.ItemData(List1.ListCount - 1) = mo.hModule
  371. Loop While ModuleNext(mo)
  372. screen.MousePointer = 0
  373. End Sub
  374. Static Sub BuildTaskList ()
  375. 'BuildTaskList: Build Task List using a GetWindow() loop (TASKMAN style)
  376. Dim te As TASKENTRY
  377. screen.MousePointer = 11
  378. yield% = DoEvents()
  379. 'Get the first window known to Windows. The Me.hWnd is just
  380. ' here because we need to pass a *valid* hWnd
  381. hWndTest% = GetWindow(Me.hWnd, GW_HWNDFIRST)
  382. 'As long as the hWnd we got is valid ...
  383. While hWndTest%
  384.     'Test to see if the associated window has a owner. If
  385.     ' it has, it's not a top-level window and we don't
  386.     ' bother with it
  387.     If GetWindow(hWndTest%, GW_OWNER) = 0 Then
  388.         'Otherwise, get the window caption (text)
  389.         buf$ = Space$(256)
  390.         res% = GetWindowText(hWndTest%, buf$, 256)
  391.         If res% > 1 Then
  392.             'And if that went well add it to our list ...
  393.             GetTaskEntry GetWindowTask(hWndTest%), te
  394.             AddTaskEntryToList te, hWndTest%
  395.         End If
  396.     End If
  397.     'Get the handle of the next window, if any
  398.     hWndTest% = GetWindow(hWndTest%, GW_HWNDNEXT)
  399. screen.MousePointer = 0
  400. End Sub
  401. Static Sub BuildTaskList2 ()
  402. 'BuildTaskList2: Build Task List by walking the TASKENTRY struct list
  403. screen.MousePointer = 11
  404. yield% = DoEvents()
  405. Dim te As TASKENTRY
  406. te.dwSize = Len(te)
  407. If TaskFirst(te) = 0 Then
  408.     'Sanity check
  409.     MsgBox "Could not retrieve the first task in the task list. This is probably due to a corrupted system or an incompatible Windows version.", 16, "Fatal Error"
  410.     End
  411. End If
  412. 'Simply walk get all TASKENTRY structs and process 'em
  413.     AddTaskEntryToList te, 0
  414. Loop While TaskNext(te)
  415. screen.MousePointer = 0
  416. End Sub
  417. Sub CascadeWindows_Click ()
  418. 'CascadeWindows: Cascade all Windows on the Desktop
  419. 'This code is based on information and sample source code
  420. 'from UNDOCUMENTED WINDOWS
  421. 'Check SHIFT key state. If the user depresses it while
  422. '  clicking the Cascade button, do a horizontal cascade
  423. '  (stacked windows). Do a vertical cascase (windows side
  424. '  by side) otherwise. This also works with the normal
  425. '  Windows 3.1 Task Manager.
  426. If GetKeyState(VK_SHIFT) = &H8000 Then
  427.     CascadeChildWindows GetDeskTopWindow(), MDITILE_HORIZONTAL
  428.     CascadeChildWindows GetDeskTopWindow(), MDITILE_VERTICAL
  429. End If
  430. End Sub
  431. Sub ClassInfo_Click ()
  432. 'ClassInfo: display all window classes associated with the
  433. ' current task
  434. screen.MousePointer = 11
  435. CRLF$ = Chr$(13) & Chr$(10)
  436. 'Init description and list
  437. ClassList!DescLabel.Caption = "Window Class Information for " & Left$(List1.Text, InStr(List1.Text, Chr$(13)) - 1)
  438. ClassList!List2.DrawFlags(1) = &H110
  439. 'Which hModule are we looking for?
  440. hModuleTest% = GetCurrentModuleFromList%()
  441. Dim ce As CLASSENTRY, wc As WNDCLASS
  442. ce.dwSize = Len(ce)
  443. 'Get first class from TOOLHELP class list
  444. If ClassFirst(ce) = 0 Then
  445.     'Sanity check failed
  446.     MsgBox "Could not retrieve the first class in the class list. This is probably due to a corrupted system or an incompatible Windows version.", 16, "Fatal Error"
  447.     DoEnd
  448. End If
  449.     'If the window class' hInst matches the hModule we're looking for ...
  450.     If ce.hInst = hModuleTest% Then
  451.         'Get the class info ...
  452.         res% = GetClassInfo(ce.hInst, ce.szClassName, wc)
  453.         'Add it to our list
  454.         ClassList!List2.AddItem "Class: " & ZTrim$(ce.szClassName) & CRLF$ & XlateClassStyle$(wc.style) & CRLF$ & "hInstance=" & Hex4$(wc.hInstance) & ", hIcon=" & Hex4$(wc.hIcon) & ", hCursor=" & Hex4$(wc.hCursor) & ", hBrush=" & Hex4$(wc.hbrBackground)
  455.     End If
  456. 'Get next window class, if any
  457. Loop While ClassNext(ce)
  458. screen.MousePointer = 0
  459. 'Show class list form until user closes it
  460. ClassList.Show 1
  461. End Sub
  462. Sub CloseTask_Click ()
  463. 'CloseTask_Click: end the selected task
  464. 'Is the user trying to close a DOS box?
  465. If IsWinOldApTask(GetCurrentTaskFromList%()) Then
  466.     'If so, ask him/her if he/she is *really* sure about that
  467.     If MsgBox("The effects of closing a DOS box this way might surprise you. Continue anyway?", 36, "Government Health Warning") <> 6 Then
  468.         Exit Sub
  469.     End If
  470. End If
  471. 'Post a WM_QUIT message to the application window
  472. res% = PostMessage(List1.ItemData(List1.ListIndex), WM_QUIT, 0, 0&)
  473. 'Give Windows time to catch up
  474. yield% = DoEvents()
  475. 'And do some catching up of our own
  476. Call RefreshList_Click
  477. End Sub
  478. Sub Form_KeyUp (KeyCode As Integer, Shift As Integer)
  479. 'Form_Keyup: check if a certain key combination was pressed,
  480. ' and act accordingly
  481. 'Alt+F4?
  482. If (KeyCode = 115) And (Shift = 4) Then DoEnd
  483. 'Alt+Space?
  484. If (KeyCode = 18) And (Shift = 0) Then ShowSysMenu
  485. 'Escape?
  486. If (KeyCode = 27) And (Shift = 0) Then mInSysMenu = False
  487. End Sub
  488. Sub Form_Load ()
  489. 'Get our Instance Handle
  490. hInst% = GetWindowWord(Me.hWnd, GWW_HINSTANCE)
  491. 'Make our window topmost ('floating')
  492. res% = SetWindowPos(Me.hWnd, -1, 0, 0, 0, 0, 3)
  493. 'Init the Message Blaster
  494. Msg1.hWndTarget = Me.hWnd 'Set target form
  495. 'Intercept 'COMMAND' message so we can handle the Move, Close and 'On Top' commands ourselves
  496. Msg1.MsgList(0) = WM_COMMAND: Msg1.MsgPassage(0) = PREPROCESS
  497. 'Intercept 'ACTIVATE' message so we can change the caption color if our window gets (de)activated
  498. Msg1.MsgList(1) = WM_NCACTIVATE: Msg1.MsgPassage(1) = POSTPROCESS
  499. 'Intercept 'HIT TEST' message to allow us to determine which part of the form the mouse cursor is over
  500. Msg1.MsgList(2) = WM_NCHITTEST: Msg1.MsgPassage(2) = EATMESSAGE
  501. 'Intercept 'Left BUTTON DBLCLK' message (ends app)
  502. Msg1.MsgList(3) = WM_NCLBUTTONDBLCLK: Msg1.MsgPassage(3) = EATMESSAGE
  503. 'Intercept 'Left BUTTON DOWN' message (show our system menu)
  504. Msg1.MsgList(4) = WM_NCLBUTTONDOWN: Msg1.MsgPassage(4) = POSTPROCESS
  505. 'Intercept undocumented Window creation/destruction messages
  506. Msg1.MsgList(5) = WM_OTHERWINDOWCREATED: Msg1.MsgPassage(5) = EATMESSAGE
  507. Msg1.MsgList(6) = WM_OTHERWINDOWDESTROYED: Msg1.MsgPassage(6) = EATMESSAGE
  508. 'Set ScaleMode to Pixels
  509. Me.ScaleMode = 3
  510. 'Get color to use to draw window caption
  511. mCaptionColor& = GetSysColor(COLOR_ACTIVECAPTION) And &HFFFFFF
  512. 'Crate our 'system menu'
  513. mhSysMenu = CreatePopupMenu()
  514. res% = AppendMenu(mhSysMenu, MF_ENABLED Or MF_STRING, IDM_SYSMOVE, "&Move")
  515. res% = AppendMenu(mhSysMenu, MF_ENABLED Or MF_STRING, IDM_SYSCLOSE, "&Close  Alt+F4")
  516. res% = AppendMenu(mhSysMenu, MF_SEPARATOR, 0, "")
  517. res% = AppendMenu(mhSysMenu, MF_ENABLED Or MF_STRING Or MF_CHECKED, IDM_FLOAT, "&Always on Top")
  518. 'Set bounding rectangle for screen
  519. mScreenRect.Left = 0
  520. mScreenRect.right = screen.Width / screen.TwipsPerPixelX
  521. mScreenRect.Top = 0
  522. mScreenRect.bottom = screen.Height / screen.TwipsPerPixelY
  523. 'Set up multicolumn list box
  524. List1.ItemLength(1) = 650
  525. List1.DrawFlags(1) = &H100
  526. 'Build list for the first time
  527. Call RefreshList_Click
  528. End Sub
  529. Sub Form_Paint ()
  530. 'Form_Paint: paint the 'fake' window caption onto our (captionless) window
  531. 'Taken from SMALLCAP with some small modifications
  532. 'Paint caption background
  533. Line (1, -1)-Step(Me.Width, 15), mCaptionColor&, BF
  534. 'Horizontal line under caption
  535. Line (0, 14)-Step(Me.ScaleWidth, 0), QBColor(0)
  536. 'Vertical line beteen control menu and caption
  537. Line (12, 0)-Step(0, 15), QBColor(0)
  538. 'Background for control menu
  539. Line (1, 0)-Step(10, 13), QBColor(7), BF
  540. 'Box for bar in control menu
  541. Line (3, 5)-Step(5, 2), QBColor(0), B
  542. 'Line inside bar in control menu
  543. Line (4, 6)-Step(4, 0), QBColor(15)
  544. 'Vertical shadow on bar in control menu
  545. Line (9, 6)-Step(0, 3), QBColor(8)
  546. 'Horizontal shadow on bar in control menu
  547. Line (4, 8)-Step(5, 0), QBColor(8)
  548. End Sub
  549. Static Function GetCurrentModuleFromList% ()
  550. 'Extract the hModule value from the currently selected task
  551. tmp$ = List1.List(List1.ListIndex)
  552. x% = InStr(tmp$, "hModule=") + 8
  553. x2% = Len(tmp$) + 1
  554. GetCurrentModuleFromList% = Val("&H" & Mid$(tmp$, x%, x2% - x%))
  555. End Function
  556. Static Function GetCurrentTaskFromList% ()
  557. 'Extract the hTask value from the currently selected task
  558. tmp$ = List1.List(List1.ListIndex)
  559. x% = InStr(tmp$, "hTask=") + 6
  560. x2% = InStr(x%, tmp$, " ")
  561. GetCurrentTaskFromList% = Val("&H" & Mid$(tmp$, x%, x2% - x%))
  562. End Function
  563. Static Function GetCurrentUsageFromList% ()
  564. 'Extract the wcUsage value from the currently selected task
  565. tmp$ = List1.List(List1.ListIndex)
  566. x% = InStr(tmp$, "wcUsage=") + 8
  567. x2% = InStr(x%, tmp$, " ")
  568. GetCurrentUsageFromList% = Val("&H" & Mid$(tmp$, x%, x2% - x%))
  569. End Function
  570. Static Sub GetTaskEntry (hTask%, te As TASKENTRY)
  571. 'GetTaskEntry: Get TASKENTRY structure for a given hTask
  572. te.dwSize = Len(te)
  573. If TaskFirst(te) = 0 Then
  574.     MsgBox "Could not retrieve the first task in the task list. This is probably due to a corrupted system or an incompatible Windows version.", 16, "Fatal Error"
  575.     DoEnd
  576. End If
  577.     If te.hTask = hTask% Then Exit Sub
  578. Loop While TaskNext(te)
  579. MsgBox "TASKENTRY for hTask not found", 16, "Fatal Internal Error"
  580. End Sub
  581. Sub List1_Click ()
  582. If List1.ListIndex > -1 Then
  583.     ClassInfo.Enabled = True
  584.     If Not UseModules.Value Then SwitchTo.Enabled = True
  585.     If Not UseModules.Value Then CloseTask.Enabled = True
  586.     NukeTask.Enabled = True
  587. End If
  588. End Sub
  589. Sub Msg1_Message (MsgVal As Integer, wParam As Integer, lParam As Long, ReturnVal As Long)
  590. 'Msg1_Message: handle Windows messages
  591. 'Adapted from code in SMALLCAP (see TASKLIST.WRI for details)
  592. 'Flag to keep 'floating' status
  593. Static MenuFlag%
  594. 'Check the message we just got
  595. Select Case MsgVal
  596.         
  597.     'Did we get (de)activated?
  598.     Case WM_NCACTIVATE
  599.         If wParam% Then
  600.             'Draw 'active' caption
  601.             mCaptionColor& = GetSysColor(COLOR_ACTIVECAPTION) And &HFFFFFF
  602.         Else
  603.             'Draw 'inactive' caption
  604.             mCaptionColor& = GetSysColor(COLOR_INACTIVECAPTION) And &HFFFFFF
  605.         End If
  606.         Me.Refresh
  607.         
  608.     'Was the mouse moved over our form?
  609.     Case WM_NCHITTEST
  610.         mxPos% = (lParam And &HFFFF&)
  611.         myPos% = (lParam / 65536)
  612.         mFormTop% = Top / screen.TwipsPerPixelY
  613.         mFormLeft% = Left / screen.TwipsPerPixelX
  614.         'Is it now over the caption bar?
  615.         If (myPos% - mFormTop% < 20) And (mxPos% - mFormLeft% > 17) Then
  616.             ReturnVal = HTCAPTION
  617.             mInSysMenu% = False
  618.         'Is it within the System Menu box?
  619.         ElseIf (myPos% - mFormTop% < 20) And (mxPos% - mFormLeft% < 20) Then
  620.             ReturnVal = HTSYSMENU
  621.         'Otherwise it's in the client area ...
  622.         Else
  623.             ReturnVal = HTCLIENT
  624.             mInSysMenu% = False
  625.         End If
  626.         
  627.     'Was there a dubble click with the left mouse button?
  628.     Case WM_NCLBUTTONDBLCLK
  629.         'If the cursor was within the system menu box, exit
  630.         If wParam% = HTSYSMENU Then
  631.             DoEnd
  632.         End If
  633.         
  634.     'Was the left mouse button pressed?
  635.      Case WM_NCLBUTTONDOWN
  636.         'If the cursor was in the system menu box ...
  637.         If wParam% = HTSYSMENU Then
  638.             'Check if we're currently showing the system menu
  639.             If mInSysMenu% Then
  640.                 'And if yes, do nothing and reset flag
  641.                 '(menu will 'disappear' later because of the click)
  642.                 mInSysMenu% = False
  643.                 Exit Sub
  644.             Else
  645.                 'Otherwise, start showing the menu
  646.                 ShowSysMenu
  647.             End If
  648.         End If
  649.         
  650.     'System command?
  651.     Case WM_COMMAND
  652.         Select Case wParam%
  653.             Case IDM_SYSMOVE
  654.                 'Allow user to move the form
  655.                 rc& = SendMessage(Me.hWnd, WM_SYSCOMMAND, SC_MOVE, 0)
  656.             Case IDM_SYSCLOSE
  657.                 'Close -- exit app
  658.                 DoEnd
  659.             Case IDM_FLOAT
  660.                 'Toggle floating
  661.                 MenuFlag% = Not MenuFlag%
  662.                 If MenuFlag% Then
  663.                     'Make our window non-topmost
  664.                     res% = SetWindowPos(Me.hWnd, -2, 0, 0, 0, 0, 3)
  665.                     'And uncheck the menu option
  666.                     res% = ModifyMenu(mhSysMenu%, 3, MF_ENABLED Or MF_STRING Or MF_BYPOSITION, IDM_FLOAT, "&Always on Top")
  667.                 Else
  668.                     'Make our window topmost
  669.                     res% = SetWindowPos(Me.hWnd, -1, 0, 0, 0, 0, 3)
  670.                     'And check the menu option
  671.                     res% = ModifyMenu(mhSysMenu%, 3, MF_ENABLED Or MF_STRING Or MF_CHECKED Or MF_BYPOSITION, IDM_FLOAT, "&Always on Top")
  672.                 End If
  673.         
  674.         End Select
  675.     'Did another Window get created/destroyed (so we should refresh)?
  676.     Case WM_OTHERWINDOWCREATED, WM_OTHERWINDOWDESTROYED
  677.         MsgBox "WM_OTHERWINDOWxxx received", 64, "Test"
  678.         Call RefreshList_Click
  679. End Select
  680. End Sub
  681. Sub NukeTask_Click ()
  682. 'This button does something completely different depending
  683. 'on the kind of list displayed:
  684. If Not UseModules.Value Then
  685.     'Task list: close app
  686.     If MsgBox("Closing this app the hard way might reduce your once-working Windows system to a huge GPF-feast. Continue anyway?", 36, "Government Health Warning") = 6 Then
  687.         TerminateApp GetCurrentTaskFromList%(), 1
  688.     End If
  689.     'Module list: unload module
  690.     If List1.ListIndex < 7 Then
  691.         tmp$ = "Unloading a Windows Kernel module will CRASH the system"
  692.     Else
  693.         tmp$ = "Unloading a module may crash the system"
  694.     End If
  695.     If MsgBox(tmp$ & ". Continue anyway?", 36, "Government Health Warning") = 6 Then
  696.         For a% = 1 To GetCurrentUsageFromList%()
  697.             FreeModule List1.ItemData(List1.ListIndex)
  698.         Next a%
  699.     End If
  700. End If
  701. yield% = DoEvents()
  702. Call RefreshList_Click
  703. End Sub
  704. Sub RefreshList_Click ()
  705. 'RefreshList_Click: Decide what kind of list to display,
  706. '   update buttons accordingly and call list function
  707. List1.Clear
  708. ClassInfo.Enabled = False
  709. SwitchTo.Enabled = False
  710. CloseTask.Enabled = False
  711. NukeTask.Enabled = False
  712. If UseWins.Value Or UseTasks.Value Then
  713.     NukeTask.Caption = "&Nuke task"
  714.     Call BuildTaskList
  715. ElseIf UseModules.Value Then
  716.     NukeTask.Caption = "&Unload module"
  717.     Call BuildModuleList
  718.     MsgBox "I'm confused!", 64, "Nothing to refresh"
  719. End If
  720. End Sub
  721. Sub RunProgram_Click ()
  722. 'RunProgram_Click: ask user for a program to run and do it
  723. On Local Error Resume Next
  724. resp$ = InputBox$("Enter command line", "Run")
  725. If Len(resp$) Then
  726.     Err = 0
  727.     pid% = Shell(resp$)
  728.     If Err Then
  729.         MsgBox Error$(Err), 48, "Cannot execute"
  730.     Else
  731.         yield% = DoEvents()
  732.         Call RefreshList_Click
  733.     End If
  734. End If
  735. End Sub
  736. Sub ShowSysMenu ()
  737. 'ShowSysMenu: Drop down our own 'system menu'
  738. 'Adapted from code in SMALLCAP (see TASKLIST.WRI)
  739. InPixels% = Me.ScaleWidth
  740. Me.ScaleMode = 1
  741. 'Determine if we should show the menu below or above our window
  742. x% = (Left) \ (Me.ScaleWidth \ InPixels)
  743. Y% = (9 * screen.TwipsPerPixelY + (Me.Top + (Me.Height - Me.ScaleHeight - (Me.Width - Me.ScaleWidth)))) \ (Me.ScaleWidth \ InPixels)
  744. ScaleMode = 3
  745. If (Y% + (3 * GetSystemMetrics(SM_CYMENU))) > (screen.Height / screen.TwipsPerPixelY) Then
  746.     res% = TrackPopupMenu(mhSysMenu%, 0, x%, Y% - (3 * GetSystemMetrics(SM_CYMENU)) - 9, 0, Me.hWnd, mScreenRect)
  747.     res% = TrackPopupMenu(mhSysMenu%, 0, x%, Y% + 5, 0, Me.hWnd, mScreenRect)
  748. End If
  749. 'Set global flag to indicate system menu is being shown
  750. mInSysMenu% = True
  751. End Sub
  752. Sub SwitchTo_Click ()
  753. 'SwitchTo_Click: use SwitchToThisWindow API call to switch
  754. ' to the window associated with the selected task (ItemData
  755. ' contains the hWnd)
  756. Call SwitchToThisWindow(List1.ItemData(List1.ListIndex), 1)
  757. End Sub
  758. Sub TileWindows_Click ()
  759. 'TileWindows: Tile all Windows on the Desktop
  760. 'This code is based on information and sample source code
  761. 'from UNDOCUMENTED WINDOWS
  762. 'Check SHIFT key state. If the user depresses it while
  763. '  clicking the Tile button, do a horizontal tile
  764. '  (left to right). Do a vertical tile (top to bottom)
  765. '  This also works with the normal Windows 3.1 Task Manager.
  766. If GetKeyState(VK_SHIFT) = &H8000 Then
  767.     TileChildWindows GetDeskTopWindow(), MDITILE_HORIZONTAL
  768.     TileChildWindows GetDeskTopWindow(), MDITILE_VERTICAL
  769. End If
  770. End Sub
  771. Sub UseModules_Click ()
  772. CaptionLabel.Caption = "Module List"
  773. Call RefreshList_Click
  774. End Sub
  775. Sub UseTasks_Click ()
  776. CaptionLabel.Caption = "Task List (via TaskInfo structs)"
  777. Call RefreshList_Click
  778. End Sub
  779. Sub UseWins_Click ()
  780. CaptionLabel.Caption = "Task List (traditional)"
  781. Call RefreshList_Click
  782. End Sub
  783. Static Function XlateClassStyle$ (style%)
  784. 'XlateClassStyle$: returns a string describing the
  785. ' windows style bits (CS_xxx) for a class
  786. Dim bitvalue%(11), xlat$(11)
  787. If bitvalue%(1) <> &H1 Then
  788.     bitvalue%(1) = &H1: xlat$(1) = "VRedraw"
  789.     bitvalue%(2) = &H2: xlat$(2) = "HRedraw"
  790.     bitvalue%(3) = &H8: xlat$(3) = "DblClks"
  791.     bitvalue%(4) = &H20: xlat$(4) = "OwnDC"
  792.     bitvalue%(5) = &H40: xlat$(5) = "ClassDC"
  793.     bitvalue%(6) = &H80: xlat$(6) = "ParentDC"
  794.     bitvalue%(7) = &H200: xlat$(7) = "NoClose"
  795.     bitvalue%(8) = &H800: xlat$(8) = "SaveBits"
  796.     bitvalue%(9) = &H1000: xlat$(9) = "ByteAlignClient"
  797.     bitvalue%(10) = &H2000: xlat$(10) = "ByteAlignWindow"
  798.     bitvalue%(11) = &H4000: xlat$(11) = "GlobalClass"
  799. End If
  800. tmp$ = ""
  801. For a% = 1 To 11
  802.     If (style% And bitvalue%(a%)) = bitvalue%(a%) Then
  803.         tmp$ = tmp$ & xlat$(a%) & ", "
  804.     End If
  805. Next a%
  806. If Len(tmp$) > 2 Then
  807.     XlateClassStyle$ = Left$(tmp$, Len(tmp$) - 2)
  808.     XlateClassStyle$ = ""
  809. End If
  810. End Function
  811.